<?php echo $this->load->view('meta'); ?>
<title>xa-ncsu | calendar</title>
<link rel="stylesheet" href="<?=base_url();?>css/calendar.css" />
<script type="text/javascript" src="<?=base_url();?>js/jquery-1.2.2.pack.js"></script>
<script type="text/javascript" src="<?=base_url();?>js/jquery-impromptu.1.2.js"></script>
<link rel="stylesheet" href="<?=base_url()?>css/impromptu.css" type="text/css" media="screen" />
<script>
function vhconfirm(v,m)
        {
            if( v )
            {
                var f =  document.createElement("form");document.body.appendChild(f);f.method = "POST";f.action = $("#" + v ).attr( "href" );f.submit();
            } else
            {
                return false;
            }
        }
</script>
<?php echo $this->load->view('header'); ?>
</div>
	

<h2>calendar</h2>
<div id="full_calendar">
<div id="replace_event">
	<div class="event_container">
	<div id="event" class="left">
	<?=(isset($xalt)) ? "<a href=\"" . site_url() . "calendar/editEvent/" . $event->id . "\" style=\"text-decoration:none;\"><img src=\"" . base_url() . "img/icons/page_edit.png\" alt=\"Edit event\"/></a>" : "" ?><?=(isset($xalt)) ? "<a href=\"" . site_url() . "calendar/deleteEvent/" . $event->id . "\"	 id=\"conf" . $event->id . "\" onclick=\"$.prompt('Delete Event?',{callback: vhconfirm, buttons: { Yes : 'conf$event->id', No : false}}); return false;\"><img src=\"" .base_url() . "img/icons/delete.png\" alt=\"Delete Event\" title=\"Delete Event\" /></a>" : "" ?><?=(isset($xalt) || isset($admin)) ? "<a href=\"" . site_url() . "calendar/createItem/" . $event->id . "\" style=\"text-decoration:none;\"><img src=\"" . base_url() . "img/icons/page_edit.png\" alt=\"Edit event\"/></a>" : "" ?>
	<br />
	<?= $event->name?> @ <?=date("g:i a",mktime((int)substr($event->start,11,2),(int)substr($event->start,14,2),0,0,0,0))?> until <?=date("g:i a",mktime((int)substr($event->end,11,2),(int)substr($event->end,14,2),0,0,0,0))?>
	<? if($event->location!='')?>
	<?= ($event->location!='') ? "<p>Place: $event->location</p>" : ""?>
	<p><?= $event->description?></p>
	</div>
	<div class="item">
	<?=($items->num_rows()!=0 ? "<u>Items</u>" : "")?>
	<? foreach($items->result() as $row2): ?>
	<? if($row2->assign=="") : ?>
	<li><a href="<?=site_url()?>calendar/assignItem/<?=$row2->id?>/<?=$con_user->userid?>" id="conf<?=$row2->id?>" onclick="$.prompt('Would you like to bring this item?',{callback: vhconfirm, buttons: { Yes : 'conf<?=$row2->id?>', No : false}}); return false;" style="text-decoration:none;"><?=$row2->name?></a></li>
	<? else : ?>
	<li><?=$row2->name?></li>
	<? endif ?>
	<?php endforeach?>
	</div>
	</div>
</div>
<table class="full">
	<tr><td><?= "<a href='javascript:;' onClick=\"
	
	$.ajax({
	  url: '" . base_url() . "calendar/full/" . date("n",$date) . "/" . date("Y",strtotime("-1 year",$date)) . "/cal_only/',
	  cache: true,
	  success: function(html){
	    $('#full_calendar').html(html);
	  }
	});
	
	
	\"><<</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onClick=\"
	
	$.ajax({
	  url: '" . base_url() . "calendar/full/" . date("n",strtotime("-1 month",$date)) . "/" . date("Y",strtotime("-1 month",$date)) . "/cal_only/',
	  cache: true,
	  success: function(html){
	    $('#full_calendar').html(html);
	  }
	});
	
	\"><</a></td><td colspan='5'>" . date("F Y",$date) . "</td><td><a href='javascript:;' onClick=\"
	
	$.ajax({
	  url: '" . base_url() . "calendar/full/" . date("n",strtotime("+1 month",$date)) . "/" . date("Y",strtotime("+1 month",$date)) . "/cal_only/',
	  cache: true,
	  success: function(html){
	    $('#full_calendar').html(html);
	  }
	});
	
	\">></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onClick=\"
	
	$.ajax({
	  url: '" . base_url() . "calendar/full/" . date("n",$date) . "/" . date("Y",strtotime("+1 year",$date)) . "/cal_only/',
	  cache: true,
	  success: function(html){
	    $('#full_calendar').html(html);
	  }
	});
	
	\">>></a></td</tr>";?>
	<tr><th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr>
		<?php
		foreach ($dates as $date) { 
			echo "<tr>";
			for ($i=0;$i<7;$i++) {
				echo "<td><div class='containerr'><div class='date'>$date[$i]</div>";
				if(isset($events)){
				if(array_key_exists($date[$i],$events)){
					foreach($events[$date[$i]] as $current){
						$a = (strtotime("$current[end]") - strtotime("$current[start]"))/(60*60*24);
						if($a<1) echo "<a href='javascript:;' onClick=\"
						
						$.ajax({
						  url: '" . base_url() . "calendar/event/" . $current['id'] . "',
						  cache: true,
						  success: function(html){
						    $('#replace_event').html(html);
						  }
						});
						
						\"><div class='event'>" . date("g:ia",strtotime("$current[start]")) . " " . $current['name'] . "</div></a><br>";
						else{
							if($date[$i]==date("j",strtotime("$current[start]"))) echo "<a href='javascript:;' onClick=\"
							
							$.ajax({
							  url: '" . base_url() . "calendar/event/" . $current['id'] . "',
							  cache: true,
							  success: function(html){
							    $('#replace_event').html(html);
							  }
							});
							
							\"><div class='event'>" . date("g:ia",strtotime("$current[start]")) . " " . $current['name'] . "</div></a><br>";
							else echo "<a href='javascript:;' onClick=\"
							
							$.ajax({
							  url: '" . base_url() . "calendar/event/" . $current['id'] . "',
							  cache: true,
							  success: function(html){
							    $('#replace_event').html(html);
							  }
							});
							
							\"><div class='event'>$current[name]</div></a><br>";
						}
					}
					echo "</div></td>";
					
				}
				else{
					echo"</div></td>";
				}
			}
			else{
				echo "</div></td>";
			}	
			}
			echo "</tr>";
		}
		?>
</table>
</div>
<?=$this->load->view('footer');?>